package com.hwh.daoIm;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hwh.dao.Admin1Dao;
import com.hwh.vo.Admin1;


import JDBCUtil.UTIL;

public class Admin1DaoImp implements Admin1Dao{
	
	public Admin1 valiAdmin1(Admin1 ad) {
		Admin1 admin1 = new Admin1();
		StringBuffer sql = new StringBuffer("select * from admin1 where a_name=? and a_pwd=?");
		Connection conn = UTIL.getConn();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql.toString());
			ps.setString(1, ad.getA_name());
			ps.setString(2, ad.getA_pwd());
			rs= ps.executeQuery();
			if(rs.next()) {
				admin1 = new Admin1(rs.getInt("a_id"),rs.getString("a_name"),rs.getString("a_pwd"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				UTIL.closeConn(rs, ps, conn);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		
		return admin1;
		
	}
	
}
